#include "gd32f3x0.h"
#include "gd32f3x0_hw.h"
#include <stdio.h>
#include "Exti_Ctrl.h"
#include "Msg.h"

void Exti_Config(void)
{
    /* configure gpio_pin_0 as input */
    gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);

    /* Connect EXTI Line0 to PA0 pin */
    syscfg_exti_line_config(EXTI_SOURCE_GPIOA, EXTI_SOURCE_PIN0);

    /* Configure EXTI Line0 and its interrupt to the lowest priority*/
    exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_FALLING);

    nvic_irq_enable(EXTI0_1_IRQn, 2U, 0U);

    exti_interrupt_flag_clear(EXTI_0);
}

void Exti_IRQHandler(void)
{
    DIB542_MsgPost(DIB542_MSG_IRQ, 0);
}
